package xin.val1ant.spring_security_jpa.controller;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import xin.val1ant.spring_security_jpa.domain.User;
import xin.val1ant.spring_security_jpa.service.IUserService;


/**
 * 用户控制器.
 * 
 * @author <a href="https://waylau.com">Way Lau</a>
 * @date 2017年2月26日
 */
@Controller
@RequestMapping("/admin")
public class AdminController {
	@Autowired
	private IUserService userService;


	@GetMapping("/hello")
	public String hello(){

		return "admin/hello";
	}


	/**
	 * 查询所用用户
	 * @return
	 */
	@GetMapping("")
	public ModelAndView list(Model model) {

		List<User> list = new ArrayList<>();	// 当前所在页面数据列表
		list = userService.listUsers();
		model.addAttribute("title", "管理员管理");
		model.addAttribute("userList", list);
		return new ModelAndView("user/list", "userModel", model);
	}
 

}
